const mongoose = require('mongoose')

const FileSchema = new mongoose.Schema(
  {
    fileId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'File',
      default: function () {
        return this._id
      }
    },
    filename: { type: String, required: true }, // 存储文件名
    filePath: { type: String, required: true }, // 文件存储路径
    mimetype: { type: String, required: true }, // 文件类型
    size: { type: Number, required: true }, // 文件大小
    createdAt: { type: Date, default: Date.now }, // 创建时间
    referenced: { type: Boolean, default: false } // 是否被业务引用
  },
  { timestamps: true }
)
FileSchema.index({ fileId: 1 })
module.exports = mongoose.model('File', FileSchema)
